package com.example.springsecurity.controller;

import com.example.springsecurity.domain.SysUser;
import com.example.springsecurity.service.LoginService;
import com.example.springsecurity.uilts.ResponseResult;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;


@RestController
public class LoginController {

    @Resource
    private LoginService loginService;

    @PostMapping("user/login")
    public ResponseResult Login(SysUser sysUser){
        String token = loginService.Login(sysUser);
        HashMap<String,String> map=new HashMap<>();
        map.put("token",token);
        ResponseResult result=new ResponseResult<Map>(HttpStatus.OK.value(),"登录成功",map);
        return result;
    }


    @PostMapping("user/loginOut")
    public ResponseResult LoginOut(){
        loginService.LoginOut();
        ResponseResult responseResult = new ResponseResult<Map>(HttpStatus.OK.value(),"登出成功");
        return responseResult;
    }
}
